<?php 
// array for JSON response
$response = array();

// include db connect class
require_once __DIR__ . '/db_connect.php';

// connecting to db
$db = new DB_CONNECT();

if(isset($_GET['THANH_PHO'])){
	$city = $_GET['THANH_PHO'];
	
	mysql_query("set names 'utf8'");
	$result = mysql_query("SELECT * FROM MON_AN WHERE THANH_PHO = '$city' ORDER BY TEN_MON_AN ASC") 
		or die(mysql_error());
	
	// check for empty result
	if (mysql_num_rows($result) > 0) {
		// looping through all results
		// products node
		$response["foods"] = array();
	
		while ($row = mysql_fetch_array($result)) {
			// temp user array
			$food = array();
			$food["id"] = $row["id"];
			$food["TEN_DIA_DIEM"] = $row["TEN_DIA_DIEM"];
			$food["TEN_MON_AN"] = $row["TEN_MON_AN"];
			$food["DIA_CHI"] = $row["DIA_CHI"];
			$food["THANH_PHO"] = $row["THANH_PHO"];
			$food["SO_DIEN_THOAI"] = $row["SO_DIEN_THOAI"];
			$food["MO_TA"] = $row["MO_TA"];
			$food["LATITUDE"] = $row["LATITUDE"];
			$food["LONGITUDE"] = $row["LONGITUDE"];
			$food["LOAI_MON_AN_id"] = $row["LOAI_MON_AN_id"];
			$food["QUAN_HUYEN"] = $row["QUAN_HUYEN"];
			// push single product into final response array
			array_push($response["foods"], $food);
		}
		// success
		$response["success"] = 1;
		// echoing JSON response
		echo utf8_encode(json_encode($response));
	} else {
		// no products found
		$response["success"] = 0;
		$response["message"] = "No foods found";
	
		// echo no users JSON
		print utf8_encode(json_encode($response));
	}
	
} else {
	// required field is missing
	$response["success"] = 0;
	$response["message"] = "Required field(s) is missing";
	
	// echoing JSON response
	echo json_encode($response);
}
?>